using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using DbDiff.Common.Helper;
using DbDiff.WinClient.Helper;

namespace DbDiff.WinClient.Controls
{
	public class DataGridImageColumn:DataGridColumnStyle 
	{
		public DataGridImageColumn(PropertyDescriptor pcol) 
		{
		}
		protected override void Abort(int RowNum) 
		{
		}
		protected override bool Commit(CurrencyManager DataSource,int RowNum) 
		{
			return true;
		}
		protected override void Edit(CurrencyManager Source ,int Rownum,Rectangle Bounds, bool ReadOnly,string InstantText, bool CellIsVisible) 
		{
		}
		protected override int GetMinimumHeight() 
		{
			return 16;
		}
		protected override int GetPreferredHeight(Graphics g ,object Value) 
		{
			return 16;
		}

		protected override Size GetPreferredSize(Graphics g, object Value) 
		{
			Size PicSize = new Size(16,16);
			return PicSize;
		}
		protected override void Paint(Graphics g,Rectangle Bounds,CurrencyManager Source,int RowNum) 
		{
			string iconName;
			SolidBrush BackBrush = new SolidBrush(Color.White);
			string msg = GetColumnValueAtRow(Source, RowNum).ToString();
			switch (msg) 
			{
				case CompareMsg.MsgSame:
					iconName = "ok";
					break;
				case CompareMsg.MsgDb1Missing:
					iconName = "point_red";
					break;
				case CompareMsg.MsgDb2Missing:
					iconName = "point_red";
					break;
				case CompareMsg.MsgDifferent:
					iconName = "point_yellow";
					break;
				default:
					iconName = "point_yellow";
					break;
			}

			//IconHelper iconHelper = new IconHelper(iconName);
			//Icon icon = iconHelper.SearchIcon(IconHelper.IconDisplayType.Smallest);
			Icon icon = IconHelper.Instance.SearchIcon(iconName, IconHelper.IconDisplayType.Smallest);
			g.FillRectangle(BackBrush, Bounds.X, Bounds.Y, Bounds.Width, Bounds.Height);
			g.DrawIcon((Icon) icon, Bounds.X + ((Bounds.Width - icon.Width)>>1), Bounds.Y);
		}

		protected override void Paint(Graphics g,Rectangle Bounds,CurrencyManager Source,int RowNum,bool AlignToRight) 
		{
			string iconName;
			SolidBrush BackBrush = new SolidBrush(Color.White);
	
			string msg = GetColumnValueAtRow(Source, RowNum).ToString();
			switch (msg) 
			{
				case CompareMsg.MsgSame:
					iconName = "ok";
					break;
				case CompareMsg.MsgDb1Missing:
					iconName = "point_red";
					break;
				case CompareMsg.MsgDb2Missing:
					iconName = "point_red";
					break;
				case CompareMsg.MsgDifferent:
					iconName = "point_yellow";
					break;
				default:
					iconName = "point_yellow";
					break;
			}

			//IconHelper iconHelper = new IconHelper(iconName);
			//Icon icon = iconHelper.SearchIcon(IconHelper.IconDisplayType.Smallest);
			Icon icon = IconHelper.Instance.SearchIcon(iconName, IconHelper.IconDisplayType.Smallest);
			g.FillRectangle(BackBrush, Bounds.X, Bounds.Y, Bounds.Width, Bounds.Height);
			g.DrawIcon((Icon) icon, Bounds.X, Bounds.Y);
		}

		protected override void Paint(Graphics g,Rectangle Bounds,CurrencyManager Source,int RowNum, Brush BackBrush ,Brush ForeBrush ,bool AlignToRight) 
		{
			string iconName;
			string msg = GetColumnValueAtRow(Source, RowNum).ToString();
			switch (msg) 
			{
				case CompareMsg.MsgSame:
					iconName = "ok";
					break;
				case CompareMsg.MsgDb1Missing:
					iconName = "point_red";
					break;
				case CompareMsg.MsgDb2Missing:
					iconName = "point_red";
					break;
				case CompareMsg.MsgDifferent:
					iconName = "point_yellow";
					break;
				default:
					iconName = "point_yellow";
					break;
			}

			//IconHelper iconHelper = new IconHelper(iconName);
			//Icon icon = iconHelper.SearchIcon(IconHelper.IconDisplayType.Smallest);
			Icon icon = IconHelper.Instance.SearchIcon(iconName, IconHelper.IconDisplayType.Smallest);
			
			g.FillRectangle(BackBrush, Bounds.X, Bounds.Y, Bounds.Width, Bounds.Height);
			g.DrawIcon((Icon) icon, Bounds.X, Bounds.Y);
			
		}
	}
	public class DataGridROTextboxColumn:DataGridTextBoxColumn 
	{
		public DataGridROTextboxColumn(PropertyDescriptor pcol) 
		{
		}
		protected override void Abort(int RowNum) 
		{
		}
		protected override bool Commit(CurrencyManager DataSource,int RowNum) 
		{
			return true;
		}
		protected override void Edit(CurrencyManager Source ,int Rownum,Rectangle Bounds, bool ReadOnly,string InstantText, bool CellIsVisible) 
		{
           // if (!ReadOnly) ReadOnly = false;
		}
		protected override void Paint(Graphics g,Rectangle Bounds,CurrencyManager Source,int RowNum) 
		{
			base.Paint(g, Bounds, Source, RowNum);
		}

		protected override void Paint(Graphics g,Rectangle Bounds,CurrencyManager Source,int RowNum,bool AlignToRight) 
		{
			base.Paint(g, Bounds, Source, RowNum, AlignToRight);
		}

		protected override void Paint(Graphics g,Rectangle Bounds,CurrencyManager Source,int RowNum, Brush BackBrush ,Brush ForeBrush ,bool AlignToRight) 
		{
			base.Paint(g, Bounds, Source, RowNum, BackBrush, ForeBrush , AlignToRight);
		}
	}
}
